﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string ROT13(string input)
        {
            char[] array = input.ToCharArray();

            for (int i = 0; i < array.Length; i++)
            {
                char c = array[i];
                if (c >= 'a' && c <= 'z')
                {
                    if (c > 'm')
                    {
                        c = (char)(c - 13);  
                    }
                    else
                    {
                        c = (char)(c + 13);  
                    }
                }
                else if (c >= 'A' && c <= 'Z')
                {
                    if (c > 'M')
                    {
                        c = (char)(c - 13);  
                    }
                    else
                    {
                        c = (char)(c + 13);  
                    }
                }

                array[i] = c;
            }

            return new string(array);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string inputText = textBox1.Text;

            if (string.IsNullOrEmpty(inputText))
            {
                MessageBox.Show("请输入要加密的文本！", "提示",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            string result = ROT13(inputText);
            textBox1.Text = result;
        }
        private void btnReset_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox1.Text = "";
           textBox1.Focus();
        }
    }
}
